'use strict';
 
const Controller = require('egg').Controller;
 
class BlogController extends Controller {
    //post 创建博客
    async create() {
        const {
          ctx,
        } = this;
        const body = ctx.request.body;
        body.user_id = 1;
        const created = await ctx.service.blog.create(ctx.request.body);
        ctx.status = 201;
        ctx.body = created;
    
      }
      //del  删除博客
      async destroy() {
        const {
          ctx,
        } = this;
        const id = ctx.params.id;
        const user_id = +ctx.params.user_id;
        const res = await ctx.service.blog.del({
          id,
          user_id,
        });
        ctx.status = 200;
        ctx.body = res;
      }

     // 更新博客
      async update() {
        const {
          ctx,
        } = this;
        const id = ctx.params.id;
        const user_id = +ctx.params.user_id;
        const body = ctx.request.body;
        ctx.body = await ctx.service.blog.update({
          id,
          user_id,
          updates: body,
        });
      }
}

 
module.exports = BlogController;
